package com.dart.sys.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dart.commons.base.web.BaseController;
import com.dart.framework.annotations.Log;
import com.dart.sys.entity.Resource;
import com.dart.sys.service.ResourceService;

@RestController
@RequestMapping("/sys/resource")
public class ResourceController extends BaseController {
	
	@Autowired
	private ResourceService service ;
	
	@Log("新增资源")
	@RequestMapping(value="/add", method=RequestMethod.POST)
	public Object add(Resource entity, HttpServletRequest request, ModelMap modelMap) {
		if(this.service.insertSelective(entity)) {
			return setAjaxMapSuccess();
		} else {
			return setAjaxMapFailed();
		}
	}
	
	@Log("删除资源")
	@RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
	public Object delete(@PathVariable Integer id) {
		if(this.service.delete(id)) {
			return setAjaxMapSuccess();
		} else {
			return setAjaxMapFailed();
		}
	}
	
	@Log("修改资源")
	@RequestMapping(value="/update", method=RequestMethod.POST)
	public Object update(Resource entity) {
		if(this.service.updateSelective(entity)) {
			return setAjaxMapSuccess();
		} else {
			return setAjaxMapFailed();
		}
	}
	
	@Log("根据ID查询资源")
	@RequestMapping(value="/get/{id}", method=RequestMethod.GET)
	public Object get(@PathVariable Integer id) {
		Resource Resource = this.service.selectById(id) ;
		if(null != Resource) {
			return setAjaxMapSuccess(Resource) ;
		} else {
			return setAjaxMapFailed();
		}
	}
	
	@Log("查询资源")
	@RequestMapping(value="/list", method=RequestMethod.GET)
	public Object list(Resource entity) {
		List<Resource> selectList = this.service.selectList(entity) ;
		if(null != selectList) {
			return setAjaxMapSuccess(selectList) ;
		} else {
			return setAjaxMapFailed();
		}
	}
	
	@Log("递归查询资源")
	@RequestMapping(value="/recursive", method=RequestMethod.GET)
	public Object recursive(Integer id) {
		List<Resource> selectList = this.service.recursiveResource(id) ;
		if(null != selectList) {
			return setAjaxMapSuccess(selectList) ;
		} else {
			return setAjaxMapFailed();
		}
	}
	
	
}
